class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class Text3 {
    public boolean isSymmetric(TreeNode root) {
        if (root==null){
            return true;
        }

        return isSymmetricChild(root.left,root.right);
    }
    public boolean isSymmetricChild (TreeNode RootLeft,TreeNode RootRight) {
        if (RootLeft==null&&RootRight==null){
            return true;
        }

        if (RootLeft==null||RootRight==null){
            return false;
        }

        if (RootLeft.val != RootRight.val){
            return false;
        }

        return isSymmetricChild(RootLeft.left,RootRight.right)
                && isSymmetricChild(RootLeft.right,RootRight.left);

    }

}
